package com.qlk.test.odcinterface.rest;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.velocity.tools.config.Data;
import org.junit.Test;

import com.qlk.common.client.AbstractClient;
import com.qlk.common.utils.http.HttpClientUtil;
import com.qlk.common.utils.serialize.JsonHelper;
import com.qlk.common.utils.wrap.WrapMapper;
import com.qlk.odcinterface.domain.PmsCoupon;
import com.qlk.odcinterface.domain.PmsCouponItem;
import com.qlk.odcinterface.sdk.api.request.PmsCouponItemRequest;
import com.qlk.odcinterface.sdk.api.request.PmsCouponRequest;

/**
 * PmsCouponResourceTestCase单元测试
 * 
 * @author zhaoyanan
 * @version 2016-3-8 14:56:37
 * 
 */
public class PmsCouponResourceTestCase extends AbstractClient {
    
    @Test
    public void testGetPromotionItem() throws Exception {
        String url= Urls.API_DOMAIN + "/pmsCoupon/syncPmsCoupon";
        
        PmsCouponRequest pmsCoupon = new PmsCouponRequest();
        pmsCoupon.setId(2l);
        pmsCoupon.setCode("1604150001");
        pmsCoupon.setName("test");
        pmsCoupon.setActivityScope(1);
        pmsCoupon.setChannel("1,2,3");
        pmsCoupon.setCouponAmount("12.12");
        pmsCoupon.setCouponNumber(100l);
        pmsCoupon.setCouponType(1l);
        pmsCoupon.setFullfill("100");
        pmsCoupon.setIsEverydayLimit(0);
        pmsCoupon.setUrl("http://www.baidu.com");
        pmsCoupon.setValidWay(2);
        pmsCoupon.setValidDay(10l);
        pmsCoupon.setStatus(40);
        
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        pmsCoupon.setCreatedAt(format.parse("2016-04-15 00:01:02"));
        pmsCoupon.setUpdatedAt(format.parse("2016-04-18 00:01:02"));
        pmsCoupon.setUseBeginTime(format.parse("2016-04-16 00:01:02"));
        pmsCoupon.setUseEndTime(format.parse("2016-04-17 00:01:02"));
        pmsCoupon.setReceiveBeginTime(format.parse("2016-04-16 00:01:02"));
        pmsCoupon.setReceiveEndTime(format.parse("2016-04-17 00:01:02"));
        
        List<PmsCouponItemRequest> itemList = new ArrayList<PmsCouponItemRequest>();
        PmsCouponItemRequest item = new PmsCouponItemRequest();
        item.setGoodsId(123456);
        item.setPromotionId(pmsCoupon.getId().intValue());
        item.setSkuId(23456);
        item.setProductChannel("30");
        itemList.add(item);
        pmsCoupon.setItemList(itemList);
        
        Map<String, String> request = new HashMap<String, String>();
        
//        String content = "{\"id\":29,\"code\":\"1604190029\",\"name\":\"test041902\",\"receiveBeginTime\":\"2016-04-19 14:30:36\",\"receiveEndTime\":\"2016-04-20 15:30:40\",\"validWay\":1,\"useBeginTime\":\"2016-04-21 15:35:44\",\"useEndTime\":\"2016-04-24 18:30:47\",\"channel\":\"10\",\"couponType\":1,\"couponAmount\":\"10.00\",\"fullfill\":\"99.00\",\"couponNumber\":100,\"limitNumber\":1,\"isEverydayLimit\":1,\"activityScope\":1,\"status\":50,\"createTime\":\"2016-04-19 15:37:16\",\"updateTime\":\"2016-04-19 15:54:42\",\"yn\":1,\"itemList\":[{\"id\":495,\"promotionCode\":\"1604190029\",\"productCode\":\"203010041\",\"sku\":\"6355\",\"imgUrl\":\"{\"orig\":\"\\/o\\/oj\\/337\\/orig_336296_3.jpg\",\"w800\":\"\\/o\\/01800\\/337\\/800_336296_3.jpg\",\"w640\":\"\\/o\\/01640\\/337\\/640_336296_3.jpg\",\"w360\":\"\\/o\\/01360\\/337\\/360_336296_3.jpg\",\"w290\":\"\\/o\\/01290\\/337\\/290_336296_3.jpg\",\"w190\":\"\\/o\\/01190\\/337\\/190_336296_3.jpg\",\"w160\":\"\\/o\\/01160\\/337\\/160_336296_3.jpg\",\"w120\":\"\\/o\\/01120\\/337\\/120_336296_3.jpg\",\"w80\":\"\\/o\\/0180\\/337\\/80_336296_3.jpg\"}\",\"productName\":\"氢溴酸右美沙芬片 广东华南 15mg*12片123\",\"productStatus\":\"<b class=\"green\">上架中</b>\",\"productChannel\":\"B2C商城\",\"price\":1.00,\"promotionType\":30,\"createTime\":\"2016-04-19 15:37:27\",\"yn\":1},{\"id\":496,\"promotionCode\":\"1604190029\",\"productCode\":\"203010041\",\"sku\":\"6356\",\"imgUrl\":\"{\"orig\":\"\\/o\\/oj\\/337\\/orig_336296_3.jpg\",\"w800\":\"\\/o\\/01800\\/337\\/800_336296_3.jpg\",\"w640\":\"\\/o\\/01640\\/337\\/640_336296_3.jpg\",\"w360\":\"\\/o\\/01360\\/337\\/360_336296_3.jpg\",\"w290\":\"\\/o\\/01290\\/337\\/290_336296_3.jpg\",\"w190\":\"\\/o\\/01190\\/337\\/190_336296_3.jpg\",\"w160\":\"\\/o\\/01160\\/337\\/160_336296_3.jpg\",\"w120\":\"\\/o\\/01120\\/337\\/120_336296_3.jpg\",\"w80\":\"\\/o\\/0180\\/337\\/80_336296_3.jpg\"}\",\"productName\":\"氢溴酸右美沙芬片 广东华南 15mg*12片123\",\"productStatus\":\"<b class=\"green\">上架中</b>\",\"productChannel\":\"B2C商城\",\"price\":1.00,\"promotionType\":30,\"createTime\":\"2016-04-19 15:37:30\",\"yn\":1}]}";
        String content = "{\"id\":45,\"code\":\"1604210045\",\"name\":\"test042102\",\"receiveBeginTime\":\"2016-04-21 13:05:18\",\"receiveEndTime\":\"2016-04-22 06:10:24\",\"validWay\":1,\"useBeginTime\":\"2016-04-24 13:05:28\",\"useEndTime\":\"2016-04-28 10:10:32\",\"channel\":\"10\",\"couponType\":1,\"couponAmount\":\"10.00\",\"fullfill\":\"99.00\",\"couponNumber\":100,\"limitNumber\":1,\"isEverydayLimit\":1,\"activityScope\":1,\"status\":10,\"createTime\":\"2016-04-21 13:18:39\",\"updateTime\":\"2016-04-21 14:32:27\",\"yn\":1,\"itemList\":[{\"goodsId\":25,\"skuId\":10,\"productChannel\":\"B2C商城\",\"createTime\":\"2016-04-21 13:18:39\"},{\"goodsId\":25,\"skuId\":9,\"productChannel\":\"B2C商城\",\"createTime\":\"2016-04-21 13:18:39\"}]}";
        request.put("isStatusUpdate", "2");
        request.put("content", content);
//        request.put("preStatus", null);
        String rs = HttpClientUtil.postForObject(url, null, request);
        
        System.out.println(rs);
        WrapMapper waMapper = JsonHelper.toBean(rs, WrapMapper.class);
        
    }
}
